﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Negocios;

public partial class _Default : System.Web.UI.Page
{
    EventoBLL aBLL = new EventoBLL();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        BtNome.Enabled = true;
        BtInicio.Enabled = true;
        BtFim.Enabled = true;
        BtTipo.Enabled = true;
        BtGravar.Enabled= true;
        BtCancelar.Enabled = true;
    }
    private void cancelar()
    {
        BtCodigo.Text = "";
        BtNome.Text = "";
        BtTipo.SelectedValue = "0";
        BtFim.Text = "";
        BtInicio.Text = "";

        BtNome.Enabled = false;
        BtInicio.Enabled = false;
        BtFim.Enabled = false;
        BtTipo.Enabled = false;
        BtGravar.Enabled = false;
        BtCancelar.Enabled = false;
        BtNovo.Enabled = true;




    }

    protected void TextBox3_TextChanged(object sender, EventArgs e)
    {

    }
    protected void TextBox4_TextChanged(object sender, EventArgs e)
    {

    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }
    protected void Cancelar_Click(object sender, EventArgs e)
    {//inclua
        cancelar();

    }
protected void  BtGravar_Click(object sender, EventArgs e)
{
    //Tirar quando a autenticação estiver funcionando
    Session["usuario"] = "teste";

           try
           {
               if (BtCodigo.Text == "")
               {
                   Evento a = new Evento(Convert.ToInt32(BtTipo.SelectedValue), BtNome.Text, Convert.ToDateTime(BtInicio.Text), Convert.ToDateTime(BtFim.Text), Session["usuario"].ToString());
                   aBLL.Insere(a);
               }
               else
               {
                   Evento a = new Evento(Convert.ToInt32(BtCodigo.Text), Convert.ToInt32(BtTipo.SelectedValue), BtNome.Text, Convert.ToDateTime(BtInicio.Text), Convert.ToDateTime(BtFim.Text), Session["usuario"].ToString());
                   aBLL.Atualizar(a);
               }
               cancelar();
               BtNovo.Enabled = true;
               GridView1.DataBind();
           }
           catch (Exception ex)
           {
               lbErro.Text = ex.Message;
           }
    }

protected void LinkButton2_Click(object sender, EventArgs e)
{
    try{
    int id = Convert.ToInt32(((GridViewRow)((DataControlFieldCell)((LinkButton)sender).Parent).Parent).Cells[0].Text);
    Evento a = new Evento(id);
    aBLL.Excluir(a);
    GridView1.DataBind();
}
 catch (Exception ex)
           {
               lbErro.Text = ex.Message;
           }}
protected void LinkButton1_Click(object sender, EventArgs e)
{
    try
    {
        int id = Convert.ToInt32(((GridViewRow)((DataControlFieldCell)((LinkButton)sender).Parent).Parent).Cells[0].Text);
        Evento a = aBLL.Consultar(id);
        BtCodigo.Text = a.Codigo.ToString();
        BtNome.Text = a.Nome;
        BtInicio.Text = a.Dtinicio.ToString();
        BtFim.Text = a.Dtfim.ToString();
        BtTipo.SelectedValue = a.Tipo.ToString();


        GridView1.DataBind();

        BtNome.Enabled = true;
        BtInicio.Enabled = true;
        BtFim.Enabled = true;
        BtTipo.Enabled = true;
        BtGravar.Enabled = true;
        BtCancelar.Enabled = true;
        BtNovo.Enabled = false;
    }
    catch (Exception ex)
    {
        lbErro.Text = ex.Message;
    }
}

}
